package models

import (
	"app-box/api_error"
	"app-box/config"
	"fmt"
)

type BaseResult struct {
	Code      int
	Message   string
	Data      interface{}
	RequestID string
}

func (result *BaseResult) SetWithApiError(err api_error.ApiErrorType) {
	if err.GetIsInternalError() {
		result.Code = 500
		result.Message = "系统错误，请联系管理员"
		result.Data = nil
		if config.Mode == config.DebugMode {
			result.Message = fmt.Sprintf("%s (DebugInfo:%s , File: %s)", result.Message, err.GetMessage(), err.GetDebugInfo())
		}
	} else {
		result.Code = err.GetCode()
		result.Message = err.GetMessage()
		result.Data = nil
	}
}
